const http = require("http");
const fs = require("fs");
const url = require('url')

// nodejs 获取地址和详细信息
const server = http.createServer((req, res) => {
    console.log(req.url);
    var urlres = url.parse(req.url, true)
    console.log(urlres);
    let pathname = urlres.pathname
    console.log(`姓名是${urlres
        .query.name}年龄是${urlres.query.age}`);


    res.setHeader("Content-Type", "text/html;charest=utf-8");
    if (pathname == '/index') {
        let data = fs.readFileSync("./views/index.html");
        res.write(data);
        res.end();
    } else if (pathname == '/product') {
        let data = fs.readFileSync("./views/product.html");
        res.write(data);
        res.end();
    } else {
        //第三方资源
    }




})
server.listen(9999);